//
// Copyright (C) 2011 Steve Channell steve.channell@cepheis.com
//
// This file is part of Cephei.QL, an open-source library wrapper 
// arround QuantLib http://quantlib.org/
//
// Cephei.QL is open source software: you can redistribute it and/or modify it
// under the terms of the license.  You should have received a
// copy of the license along with this program; if not, please email
// <support@cepheis.com>. The license is also available online at
// <http://cepheis.com/license.htm>.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.  See the license for more details.
//
// Version 2.101
//#include "stdafx.h"
#include "YoYOptionletVolatilitySurface.h"
using namespace Cephei::QL::Termstructures::Volatility::Inflation;
#include <gen/QL/Times/Period.h>
#include <gen/QL/Times/Calendar.h>
#include <gen/QL/Times/DayCounter.h>
#include <gen/QL/Termstructures/VolatilityTermStructure.h>
using namespace Cephei::QL::Times;
using namespace Cephei::QL::Termstructures;
#define HANDLE
#define ABSTRACT
#undef STRUCT
Cephei::QL::Termstructures::Volatility::Inflation::CYoYOptionletVolatilitySurface::CYoYOptionletVolatilitySurface (boost::shared_ptr<QuantLib::YoYOptionletVolatilitySurface>& childNative, Object^ owner) : CVolatilityTermStructure(CYoYOptionletVolatilitySurface::typeid)
{
#ifdef HANDLE
	_phYoYOptionletVolatilitySurface = NULL;
#endif
	_ppYoYOptionletVolatilitySurface = &childNative;
    _ppVolatilityTermStructure = new boost::shared_ptr<QuantLib::VolatilityTermStructure> (boost::dynamic_pointer_cast<QuantLib::VolatilityTermStructure> (*_ppYoYOptionletVolatilitySurface));
}
Cephei::QL::Termstructures::Volatility::Inflation::CYoYOptionletVolatilitySurface::CYoYOptionletVolatilitySurface (QuantLib::YoYOptionletVolatilitySurface& childNative, Object^ owner) : CVolatilityTermStructure(CYoYOptionletVolatilitySurface::typeid)
{
#ifdef HANDLE
	_phYoYOptionletVolatilitySurface = NULL;
#endif
	_ppYoYOptionletVolatilitySurface = new boost::shared_ptr<QuantLib::YoYOptionletVolatilitySurface> (&childNative);
    _ppVolatilityTermStructure = new boost::shared_ptr<QuantLib::VolatilityTermStructure> (boost::dynamic_pointer_cast<QuantLib::VolatilityTermStructure> (*_ppYoYOptionletVolatilitySurface));
    _YoYOptionletVolatilitySurfaceOwner = owner;
    _VolatilityTermStructureOwner = owner;
}

Cephei::QL::Termstructures::Volatility::Inflation::CYoYOptionletVolatilitySurface::CYoYOptionletVolatilitySurface (CYoYOptionletVolatilitySurface^ copy) : CVolatilityTermStructure(CYoYOptionletVolatilitySurface::typeid)
{
#ifdef HANDLE
	_phYoYOptionletVolatilitySurface = NULL;
#endif
	if (copy->HasNative() != NULL)
    {
		_ppYoYOptionletVolatilitySurface = new boost::shared_ptr<QuantLib::YoYOptionletVolatilitySurface> (copy->GetShared());
        _ppVolatilityTermStructure = new boost::shared_ptr<QuantLib::VolatilityTermStructure> (boost::dynamic_pointer_cast<QuantLib::VolatilityTermStructure> (*_ppYoYOptionletVolatilitySurface));
    }
}
Cephei::QL::Termstructures::Volatility::Inflation::CYoYOptionletVolatilitySurface::CYoYOptionletVolatilitySurface (System::Type^ t) : CVolatilityTermStructure(CYoYOptionletVolatilitySurface::typeid)
{
#ifdef HANDLE
	_phYoYOptionletVolatilitySurface = NULL;
#endif
	if (!t->IsSubclassOf(CYoYOptionletVolatilitySurface::typeid))
		throw gcnew Exception ("Invalid base-case init");
}
#ifdef HANDLE
Cephei::QL::Termstructures::Volatility::Inflation::CYoYOptionletVolatilitySurface::CYoYOptionletVolatilitySurface (QuantLib::Handle<QuantLib::YoYOptionletVolatilitySurface>& childNative, Object^ owner)  : CVolatilityTermStructure(CYoYOptionletVolatilitySurface::typeid)
{
	_phYoYOptionletVolatilitySurface = &childNative;
	_ppYoYOptionletVolatilitySurface = &static_cast<boost::shared_ptr<QuantLib::YoYOptionletVolatilitySurface>>(childNative.currentLink());
    _ppVolatilityTermStructure = new boost::shared_ptr<QuantLib::VolatilityTermStructure> (boost::dynamic_pointer_cast<QuantLib::VolatilityTermStructure> (*_ppYoYOptionletVolatilitySurface));
    _YoYOptionletVolatilitySurfaceOwner = owner;
}
Cephei::QL::Termstructures::Volatility::Inflation::CYoYOptionletVolatilitySurface::CYoYOptionletVolatilitySurface (QuantLib::Handle<QuantLib::YoYOptionletVolatilitySurface> childNative)  : CVolatilityTermStructure(CYoYOptionletVolatilitySurface::typeid)
{
	_phYoYOptionletVolatilitySurface = &childNative;
	_ppYoYOptionletVolatilitySurface = &static_cast<boost::shared_ptr<QuantLib::YoYOptionletVolatilitySurface>>(childNative.currentLink());
    _ppVolatilityTermStructure = new boost::shared_ptr<QuantLib::VolatilityTermStructure> (boost::dynamic_pointer_cast<QuantLib::VolatilityTermStructure> (*_ppYoYOptionletVolatilitySurface));
}
#endif
#ifdef STRUCT
Cephei::QL::Termstructures::Volatility::Inflation::CYoYOptionletVolatilitySurface::CYoYOptionletVolatilitySurface (QuantLib::YoYOptionletVolatilitySurface childNative)  : CVolatilityTermStructure(CYoYOptionletVolatilitySurface::typeid)
{
#ifdef HANDLE
	_phYoYOptionletVolatilitySurface = NULL;
#endif
	_ppYoYOptionletVolatilitySurface = new boost::shared_ptr<QuantLib::YoYOptionletVolatilitySurface> (new QuantLib::YoYOptionletVolatilitySurface (childNative));
    _ppVolatilityTermStructure = new boost::shared_ptr<QuantLib::VolatilityTermStructure> (boost::dynamic_pointer_cast<QuantLib::VolatilityTermStructure> (*_ppYoYOptionletVolatilitySurface));
}
#endif

Cephei::QL::Termstructures::Volatility::Inflation::CYoYOptionletVolatilitySurface::~CYoYOptionletVolatilitySurface ()
{
    if (_ppYoYOptionletVolatilitySurface != NULL)
    {
	    delete _ppYoYOptionletVolatilitySurface;
        _ppYoYOptionletVolatilitySurface = NULL;
    }
}
Cephei::QL::Termstructures::Volatility::Inflation::CYoYOptionletVolatilitySurface::!CYoYOptionletVolatilitySurface ()
{
    if (_ppYoYOptionletVolatilitySurface != NULL)
    {
	    delete _ppYoYOptionletVolatilitySurface;
    }
}
QuantLib::YoYOptionletVolatilitySurface& Cephei::QL::Termstructures::Volatility::Inflation::CYoYOptionletVolatilitySurface::GetReference ()
{
    if (_ppYoYOptionletVolatilitySurface == NULL) throw gcnew NativeNullException ();
	return **_ppYoYOptionletVolatilitySurface;
}
boost::shared_ptr<QuantLib::YoYOptionletVolatilitySurface>& Cephei::QL::Termstructures::Volatility::Inflation::CYoYOptionletVolatilitySurface::GetShared ()
{
    if (_ppYoYOptionletVolatilitySurface == NULL) throw gcnew NativeNullException ();
	return *_ppYoYOptionletVolatilitySurface;
}
QuantLib::YoYOptionletVolatilitySurface* Cephei::QL::Termstructures::Volatility::Inflation::CYoYOptionletVolatilitySurface::GetPointer ()
{
    if (_ppYoYOptionletVolatilitySurface == NULL) throw gcnew NativeNullException ();
	return &**_ppYoYOptionletVolatilitySurface;
}
#ifdef HANDLE
QuantLib::Handle<QuantLib::YoYOptionletVolatilitySurface>& Cephei::QL::Termstructures::Volatility::Inflation::CYoYOptionletVolatilitySurface::GetHandle ()
{
	if (_phYoYOptionletVolatilitySurface == NULL)
	{
		_phYoYOptionletVolatilitySurface = new Handle<QuantLib::YoYOptionletVolatilitySurface> (*_ppYoYOptionletVolatilitySurface);
	}
	return *_phYoYOptionletVolatilitySurface;
}
#endif
bool Cephei::QL::Termstructures::Volatility::Inflation::CYoYOptionletVolatilitySurface::HasNative () 
{
	return (_ppYoYOptionletVolatilitySurface != NULL);
}

DateTime Cephei::QL::Termstructures::Volatility::Inflation::CYoYOptionletVolatilitySurface::BaseDate::get ()
{
    try
    {
    	QuantLib::Date _rv = (QuantLib::Date)(*_ppYoYOptionletVolatilitySurface)->baseDate ( );   
        DateTime _nrv = (DateTime)ValueHelper::Convert (_rv);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Double Cephei::QL::Termstructures::Volatility::Inflation::CYoYOptionletVolatilitySurface::BaseLevel::get ()
{
    try
    {
    	QuantLib::Volatility _rv = (QuantLib::Volatility)(*_ppYoYOptionletVolatilitySurface)->baseLevel ( );   
        Double _nrv = (Double)ValueHelper::Convert (_rv);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
QL::Times::FrequencyEnum Cephei::QL::Termstructures::Volatility::Inflation::CYoYOptionletVolatilitySurface::Frequency::get ()
{
    try
    {
    	QuantLib::Frequency _rv = (QuantLib::Frequency)(*_ppYoYOptionletVolatilitySurface)->frequency ( );   
        QL::Times::FrequencyEnum _nrv = (QL::Times::FrequencyEnum)_rv;
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Boolean Cephei::QL::Termstructures::Volatility::Inflation::CYoYOptionletVolatilitySurface::IndexIsInterpolated::get ()
{
    try
    {
    	bool _rv = (bool)(*_ppYoYOptionletVolatilitySurface)->indexIsInterpolated ( );   
        Boolean _nrv = (Boolean)ValueHelper::Convert (_rv);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Double Cephei::QL::Termstructures::Volatility::Inflation::CYoYOptionletVolatilitySurface::MaxStrike::get ()
{
    try
    {
    	QuantLib::Real _rv = (QuantLib::Real)(*_ppYoYOptionletVolatilitySurface)->maxStrike ( );   
        Double _nrv = (Double)ValueHelper::Convert (_rv);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Double Cephei::QL::Termstructures::Volatility::Inflation::CYoYOptionletVolatilitySurface::MinStrike::get ()
{
    try
    {
    	QuantLib::Real _rv = (QuantLib::Real)(*_ppYoYOptionletVolatilitySurface)->minStrike ( );   
        Double _nrv = (Double)ValueHelper::Convert (_rv);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::QL::Times::IPeriod^ Cephei::QL::Termstructures::Volatility::Inflation::CYoYOptionletVolatilitySurface::ObservationLag::get ()
{
    try
    {
    	QuantLib::Period _rv = (QuantLib::Period)(*_ppYoYOptionletVolatilitySurface)->observationLag ( );   
        Cephei::QL::Times::CPeriod^ _nrv = gcnew Cephei::QL::Times::CPeriod (_rv);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Double Cephei::QL::Termstructures::Volatility::Inflation::CYoYOptionletVolatilitySurface::TimeFromBase (DateTime date, Microsoft::FSharp::Core::FSharpOption<Cephei::QL::Times::IPeriod^>^ obsLag)
{
    CPeriod^ _CobsLag;
    try
    {
        QuantLib::Date _date = (QuantLib::Date)ValueHelper::Convert (date);
        if (Microsoft::FSharp::Core::FSharpOption<Cephei::QL::Times::IPeriod^>::IsSome::get (obsLag))
        {
            _CobsLag = safe_cast<CPeriod^> (obsLag->Value);
            _CobsLag->Lock();
        }
        QuantLib::Period& _obsLag = 
            (Microsoft::FSharp::Core::FSharpOption<Cephei::QL::Times::IPeriod^>::IsSome::get (obsLag) ? static_cast<QuantLib::Period&> (_CobsLag->GetReference ()) : QuantLib::Period(-1,Days)); //6
    	QuantLib::Time _rv = (QuantLib::Time)(*_ppYoYOptionletVolatilitySurface)->timeFromBase ( _date,  _obsLag );   
        Double _nrv = (Double)ValueHelper::Convert (_rv);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
        if (_CobsLag != nullptr) _CobsLag->Unlock();
    }
}
Double Cephei::QL::Termstructures::Volatility::Inflation::CYoYOptionletVolatilitySurface::TotalVariance (Cephei::QL::Times::IPeriod^ optionTenor, Double strike, Microsoft::FSharp::Core::FSharpOption<Cephei::QL::Times::IPeriod^>^ obsLag, Microsoft::FSharp::Core::FSharpOption<Boolean>^ extrapolate)
{
    CPeriod^ _CoptionTenor;
    CPeriod^ _CobsLag;
    try
    {
        _CoptionTenor = safe_cast<CPeriod^> (optionTenor);
        _CoptionTenor->Lock();
        QuantLib::Period& _optionTenor = static_cast<QuantLib::Period&> (_CoptionTenor->GetReference ()); 
        QuantLib::Rate _strike = (QuantLib::Rate)ValueHelper::Convert (strike);
        if (Microsoft::FSharp::Core::FSharpOption<Cephei::QL::Times::IPeriod^>::IsSome::get (obsLag))
        {
            _CobsLag = safe_cast<CPeriod^> (obsLag->Value);
            _CobsLag->Lock();
        }
        QuantLib::Period& _obsLag = 
            (Microsoft::FSharp::Core::FSharpOption<Cephei::QL::Times::IPeriod^>::IsSome::get (obsLag) ? static_cast<QuantLib::Period&> (_CobsLag->GetReference ()) : QuantLib::Period(-1,Days)); //6
        bool _extrapolate = 
            (Microsoft::FSharp::Core::FSharpOption<Boolean>::IsSome::get (extrapolate) ? (bool)ValueHelper::Convert (extrapolate->Value) : false); //9a
    	QuantLib::Volatility _rv = (QuantLib::Volatility)(*_ppYoYOptionletVolatilitySurface)->totalVariance ( _optionTenor,  _strike,  _obsLag,  _extrapolate );   
        Double _nrv = (Double)ValueHelper::Convert (_rv);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
        if (_CoptionTenor != nullptr) _CoptionTenor->Unlock();
        if (_CobsLag != nullptr) _CobsLag->Unlock();
    }
}
Double Cephei::QL::Termstructures::Volatility::Inflation::CYoYOptionletVolatilitySurface::TotalVariance (DateTime exerciseDate, Double strike, Microsoft::FSharp::Core::FSharpOption<Cephei::QL::Times::IPeriod^>^ obsLag, Microsoft::FSharp::Core::FSharpOption<Boolean>^ extrapolate)
{
    CPeriod^ _CobsLag;
    try
    {
        QuantLib::Date _exerciseDate = (QuantLib::Date)ValueHelper::Convert (exerciseDate);
        QuantLib::Rate _strike = (QuantLib::Rate)ValueHelper::Convert (strike);
        if (Microsoft::FSharp::Core::FSharpOption<Cephei::QL::Times::IPeriod^>::IsSome::get (obsLag))
        {
            _CobsLag = safe_cast<CPeriod^> (obsLag->Value);
            _CobsLag->Lock();
        }
        QuantLib::Period& _obsLag = 
            (Microsoft::FSharp::Core::FSharpOption<Cephei::QL::Times::IPeriod^>::IsSome::get (obsLag) ? static_cast<QuantLib::Period&> (_CobsLag->GetReference ()) : QuantLib::Period(-1,Days)); //6
        bool _extrapolate = 
            (Microsoft::FSharp::Core::FSharpOption<Boolean>::IsSome::get (extrapolate) ? (bool)ValueHelper::Convert (extrapolate->Value) : false); //9a
    	QuantLib::Volatility _rv = (QuantLib::Volatility)(*_ppYoYOptionletVolatilitySurface)->totalVariance ( _exerciseDate,  _strike,  _obsLag,  _extrapolate );   
        Double _nrv = (Double)ValueHelper::Convert (_rv);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
        if (_CobsLag != nullptr) _CobsLag->Unlock();
    }
}
Double Cephei::QL::Termstructures::Volatility::Inflation::CYoYOptionletVolatilitySurface::Volatility (Cephei::QL::Times::IPeriod^ optionTenor, Double strike, Microsoft::FSharp::Core::FSharpOption<Cephei::QL::Times::IPeriod^>^ obsLag, Microsoft::FSharp::Core::FSharpOption<Boolean>^ extrapolate)
{
    CPeriod^ _CoptionTenor;
    CPeriod^ _CobsLag;
    try
    {
        _CoptionTenor = safe_cast<CPeriod^> (optionTenor);
        _CoptionTenor->Lock();
        QuantLib::Period& _optionTenor = static_cast<QuantLib::Period&> (_CoptionTenor->GetReference ()); 
        QuantLib::Rate _strike = (QuantLib::Rate)ValueHelper::Convert (strike);
        if (Microsoft::FSharp::Core::FSharpOption<Cephei::QL::Times::IPeriod^>::IsSome::get (obsLag))
        {
            _CobsLag = safe_cast<CPeriod^> (obsLag->Value);
            _CobsLag->Lock();
        }
        QuantLib::Period& _obsLag = 
            (Microsoft::FSharp::Core::FSharpOption<Cephei::QL::Times::IPeriod^>::IsSome::get (obsLag) ? static_cast<QuantLib::Period&> (_CobsLag->GetReference ()) : QuantLib::Period(-1,Days)); //6
        bool _extrapolate = 
            (Microsoft::FSharp::Core::FSharpOption<Boolean>::IsSome::get (extrapolate) ? (bool)ValueHelper::Convert (extrapolate->Value) : false); //9a
    	QuantLib::Volatility _rv = (QuantLib::Volatility)(*_ppYoYOptionletVolatilitySurface)->volatility ( _optionTenor,  _strike,  _obsLag,  _extrapolate );   
        Double _nrv = (Double)ValueHelper::Convert (_rv);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
        if (_CoptionTenor != nullptr) _CoptionTenor->Unlock();
        if (_CobsLag != nullptr) _CobsLag->Unlock();
    }
}
Double Cephei::QL::Termstructures::Volatility::Inflation::CYoYOptionletVolatilitySurface::Volatility (DateTime maturityDate, Double strike, Microsoft::FSharp::Core::FSharpOption<Cephei::QL::Times::IPeriod^>^ obsLag, Microsoft::FSharp::Core::FSharpOption<Boolean>^ extrapolate)
{
    CPeriod^ _CobsLag;
    try
    {
        QuantLib::Date _maturityDate = (QuantLib::Date)ValueHelper::Convert (maturityDate);
        QuantLib::Rate _strike = (QuantLib::Rate)ValueHelper::Convert (strike);
        if (Microsoft::FSharp::Core::FSharpOption<Cephei::QL::Times::IPeriod^>::IsSome::get (obsLag))
        {
            _CobsLag = safe_cast<CPeriod^> (obsLag->Value);
            _CobsLag->Lock();
        }
        QuantLib::Period& _obsLag = 
            (Microsoft::FSharp::Core::FSharpOption<Cephei::QL::Times::IPeriod^>::IsSome::get (obsLag) ? static_cast<QuantLib::Period&> (_CobsLag->GetReference ()) : QuantLib::Period(-1,Days)); //6
        bool _extrapolate = 
            (Microsoft::FSharp::Core::FSharpOption<Boolean>::IsSome::get (extrapolate) ? (bool)ValueHelper::Convert (extrapolate->Value) : false); //9a
    	QuantLib::Volatility _rv = (QuantLib::Volatility)(*_ppYoYOptionletVolatilitySurface)->volatility ( _maturityDate,  _strike,  _obsLag,  _extrapolate );   
        Double _nrv = (Double)ValueHelper::Convert (_rv);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
        if (_CobsLag != nullptr) _CobsLag->Unlock();
    }
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Factory class

